home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
276-300
/
285
/
liner
/
source
/
disk.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-14
|
3KB
|
108 lines
#define BUFF_SIZE sizeof(struct LineItem)
WriteItemList(FileName) /*Write the item list to disk*/
char *FileName;
{
struct FileHandle *fp;
struct LineItem *buffer,*CurItem;
UBYTE StartDouble;
if((fp=(struct FileHandle *)Open(FileName,MODE_NEWFILE))==NULL)
{
TitleError("Can't open file for save!");
return(FALSE);
}
buffer=(struct LineItem *)AllocMem(BUFF_SIZE,MEMF_CHIP|MEMF_CLEAR);
strcpy(buffer->Text,"LFDB"); /*ID: Liner Form Data Block*/
/*Store StaringLevel & DoubleSpc as one byte on disk*/
StartDouble=StartingLevel+(DoubleSpc*32);
buffer->Text[4]=StartDouble;
buffer->Text[5]=0;
Write(fp,buffer,BUFF_SIZE);
CurItem=(struct LineItem *)FirstItem;
do
{
buffer->Level=CurItem->Level;
buffer->ItemNumber=CurItem->ItemNumber;
strcpy(buffer->Text,CurItem->Text);
Write(fp,buffer,BUFF_SIZE);
CurItem=(struct LineItem *)CurItem->NextItem;
}
while(CurItem != NULL);
FreeMem(buffer,BUFF_SIZE);
Close(fp);
return(TRUE);
}
ReadItemList(FileName) /*Read an item list from disk*/
char *FileName;
{
struct FileHandle *fp;
struct LineItem *buffer,*CurItem;
int len;
char TempIndent;
if((fp=(struct FileHandle *)Open(FileName,MODE_OLDFILE))==NULL)
{
TitleError("Can't open file for read!");
return(FALSE);
}
FreeListMem(FirstItem,LastItem); /*Get rid of old outline*/
buffer=(struct LineItem *)AllocMem(BUFF_SIZE,MEMF_CHIP|MEMF_CLEAR);
Read(fp,buffer,BUFF_SIZE);
TempIndent=buffer->Text[4];
buffer->Text[4]=NULL;
if(strcmp(buffer->Text,"LFDB"))
{
close(fp);
return(FALSE);
}
if(TempIndent>=32) /*If double spaced...*/
{
DoubleSpc=1;
MenuItem1.Flags=CHECKIT+ITEMTEXT+COMMSEQ+MENUTOGGLE+
ITEMENABLED+HIGHCOMP+CHECKED;
TempIndent-=32; /*Removed double spacing flag*/
}
else
{
DoubleSpc=0;
MenuItem1.Flags=CHECKIT+ITEMTEXT+COMMSEQ+MENUTOGGLE+
ITEMENABLED+HIGHCOMP;
}
SubItems[StartingLevel]->Flags-=CHECKED;
StartingLevel=(TempIndent < 6) ? TempIndent : 6;
SubItems[StartingLevel]->Flags+=CHECKED;
CurItem=FirstItem=FirstScrnItem=(struct LineItem *)InsertItem(NULL,NULL);
len=Read(fp,buffer,BUFF_SIZE);
while(len > 0)
{
CurItem->ItemNumber=buffer->ItemNumber;
CurItem->Level=buffer->Level;
strcpy(CurItem->Text,buffer->Text);
len=Read(fp,buffer,BUFF_SIZE);
CurItem=(struct LineItem *)InsertItem(NULL,CurItem);
}
LastItem=(struct LineItem *)CurItem->PrevItem;
LastItem->NextItem=NULL;
FreeMem(CurItem,sizeof(struct LineItem));
FreeMem(buffer,BUFF_SIZE);
Close(fp);
PrintItemList(FirstItem,1);
CurrentItem=(struct LineItem *)FirstItem;
PlotCursor(MinX(CurrentItem),1);
return(TRUE);
}